<?php

namespace App\Containers\AppSection\BankDetail\Actions;

use App\Containers\AppSection\BankDetail\Models\BankDetail;
use App\Containers\AppSection\BankDetail\Tasks\UpdateBankDetailTask;
use App\Containers\AppSection\BankDetail\UI\API\Requests\UpdateBankDetailRequest;
use App\Containers\AppSection\Log\Tasks\CreateLogTask;
use App\Ship\Parents\Actions\Action;

class UpdateBankDetailAction extends Action
{
    public function run($id, UpdateBankDetailRequest $request): BankDetail
    {
        $data = $request->sanitizeInput([
            'name',
            'bik',
            'correspondent_account',
            'inn',
            'checking_account'
        ]);

        $bankDetails = app(UpdateBankDetailTask::class)->run($id, $data);

        app(CreateLogTask::class)->run($request->profile()->id, "Банковские реквизиты №{$bankDetails->id} обновлены", 'bankDetail');

        return $bankDetails;
    }
}
